﻿package Albums 
{
	import com.greensock.TweenLite;
	import Common.Constants;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import Fonts.CalibriEmbed;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;
	
	/**
	 * ...
	 * @author Serg de Adelantado
	 */
	public class AlbumCreateIcon extends AbstractIcon 
	{
		private var FIcon:Bitmap;
		private var FBackground:Sprite;
		private var FText:TextField;
		private var FHighlite:Sprite;
		
		public function AlbumCreateIcon() 
		{
			FBackground = new Sprite();
			addChild(FBackground);
			FBackground.mouseEnabled = false;			
			FIcon = new Bitmap(new BigPlusIcon());			
			FIcon.scaleX = FIcon.scaleY = 0.75;			
			FIcon.alpha = 0.75;			
			FBackground.filters = [new DropShadowFilter(4, -90, 0, 0.5, 0, 5, 1, 3, true)];
			useHandCursor = buttonMode = true;
			
			FHighlite = new Sprite();
			FHighlite.mouseEnabled = false;
			FHighlite.alpha = 0;
			addChild(FHighlite);
			addChild(FIcon);
			FHighlite.filters = [new DropShadowFilter(4, -90, 0, 0.25, 0, 5, 1, 3, true)];
			
			FText = new TextField();
			FText.multiline = false;
			FText.textColor = Constants.ALBUM_TEXT;
			var vFormat:TextFormat = new TextFormat();
			vFormat.font = new CalibriEmbed().fontName;	
			FText.embedFonts = true;			
			FText.defaultTextFormat = vFormat;
			FText.text = 'Добавить номер';
			FText.width = FText.textWidth + 5;
			FText.height = FText.textHeight + 4;
			FText.selectable = false;
			FText.mouseEnabled = false;
			addChild(FText);
			
			addEventListener(MouseEvent.MOUSE_OVER, OnMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, OnMouseOut);
		}
		
		override protected function Draw():void 
		{
			FBackground.graphics.clear();
			FBackground.graphics.beginFill(BACKGROUND_COLOR, Constants.ALBUM_ALPHA);
			FBackground.graphics.drawRect(0, 0, FWidth, FHeight);
			FBackground.graphics.endFill();
			
			FHighlite.graphics.clear();
			FHighlite.graphics.beginFill(HIGHLITE_COLOR, Constants.ALBUM_ALPHA + 0.2);
			FHighlite.graphics.drawRect(0, 0, FWidth, FHeight);
			FHighlite.graphics.endFill();			
		}
		
		override public function SetSize(AWidth:Number, AHeight:Number):void
		{
			FWidth = AWidth;
			FHeight = AHeight;			
			Draw();						
			FText.x = (FWidth - FText.width) / 2;
			FText.y = FHeight - FText.height;
			FIcon.x = (FWidth - FIcon.width) / 2;
			FIcon.y = 20;
		}
		
		protected function OnMouseOver(e:MouseEvent):void 
		{
			TweenLite.to(FHighlite, 0.5, { alpha: 1} );
		}
		
		protected function OnMouseOut(e:MouseEvent):void 
		{
			TweenLite.to(FHighlite, 0.5, { alpha: 0} );
		}
	}
}